<?php

namespace app\api\controller;

use think\Db;
use app\common\controller\Api;

/****
 * Class    Goodscategory
 * @name    商品分类API文件
 * @author  晓月老板<1434926265@qq.com>
 * @date    2020/05/21 09:24 AM
 * @package app\api\controller
 */
class GoodsCategory extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /***
     * @name    获取首页商品列表<按照后台权重排序>
     * @author  晓月老板<1434926265@qq.com>
     * @date    2020/05/21 11:17 AM
     * @return  string<json>
     */
    public function category_list()
    {


        // 获取店铺ID
        $store_id = $this->request->request("store_id",0,"intval");

        // 查询商品数据
        $data['list'] = Db::name('shopro_category')->where(array('status'=>'normal','store_id'=>$store_id))->order('weigh desc')->select();

        $this->success('请求成功', $data);

    }

    /***
     * @name    分类商品详情API接口
     * @author  晓月老板<1434926265@qq.com>
     * @date    2020/05/21 09:38 AM
     * @return  string<json>
     */
    public function category_goods_list()
    {

        // 获取分类ID
        $category_id = $this->request->request("category_id",0,"intval");

        if($category_id == 0){
            $this->error("参数错误");
        }

        // 查询分类商品数据
        $goods_list = Db::name('shopro_goods')->where(array('category_ids'=>$category_id,'status'=>'up'))->select();

        // 赋值
        $data['goods_list'] = $goods_list;

        $this->success('请求成功', $data);

    }


}
